add_custom_target(libc_time_unittests)

add_libc_unittest(
  asctime_test
  SUITE
    libc_time_unittests
  SRCS
    asctime_test.cpp
  HDRS
    TmHelper.h
    TmMatcher.h
  CXX_STANDARD
    20
  DEPENDS
    libc.src.time.asctime
)

add_libc_unittest(
  asctime_r_test
  SUITE
    libc_time_unittests
  SRCS
    asctime_r_test.cpp
  HDRS
    TmHelper.h
    TmMatcher.h
  CXX_STANDARD
    20
  DEPENDS
    libc.src.time.asctime_r
)

add_libc_unittest(
  clock_gettime_test
  SUITE
    libc_time_unittests
  SRCS
  clock_gettime_test.cpp
  DEPENDS
    libc.src.time.clock_gettime
)

add_libc_unittest(
  difftime_test
  SUITE
    libc_time_unittests
  SRCS
    difftime_test.cpp
  DEPENDS
    libc.src.time.difftime
)

add_libc_unittest(
  gettimeofday_test
  SUITE
    libc_time_unittests
  SRCS
    gettimeofday_test.cpp
  DEPENDS
    libc.include.time
    libc.src.time.gettimeofday
)

add_libc_unittest(
  gmtime_test
  SUITE
    libc_time_unittests
  SRCS
    gmtime_test.cpp
  HDRS
    TmMatcher.h
  DEPENDS
    libc.src.time.gmtime
)

add_libc_unittest(
  gmtime_r_test
  SUITE
    libc_time_unittests
  SRCS
    gmtime_r_test.cpp
  HDRS
    TmMatcher.h
  DEPENDS
    libc.src.time.gmtime_r
)

add_libc_unittest(
  mktime_test
  SUITE
    libc_time_unittests
  SRCS
    mktime_test.cpp
  HDRS
    TmHelper.h
    TmMatcher.h
  CXX_STANDARD
    20
  DEPENDS
    libc.src.time.mktime
)

# Sleeping is not supported on older NVPTX architectures.
set(unsupported_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62")
if (NOT ("${LIBC_GPU_TARGET_ARCHITECTURE}" IN_LIST unsupported_architectures))
  add_libc_test(
    nanosleep_test
    SUITE
      libc_time_unittests
    SRCS
      nanosleep_test.cpp
    DEPENDS
      libc.include.time
      libc.src.time.nanosleep
      libc.src.errno.errno
  )
endif()

add_libc_unittest(
  time_test
  SUITE
    libc_time_unittests
  SRCS
    time_test.cpp
  DEPENDS
    libc.include.time
    libc.src.time.time
    libc.src.errno.errno
)

add_libc_test(
  clock_test
  SUITE
    libc_time_unittests
  SRCS
    clock_test.cpp
  DEPENDS
    libc.include.time
    libc.src.time.clock
    libc.src.errno.errno
)
